package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.List;
import java.util.Map;
@RestController
public class Controller {
    @Autowired
    ServiceImpl service;
    @RequestMapping("/show")
    //折线图
    public Object show(String nowDate){
        List<Map> show = service.show(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONObject dataobject = new JSONObject();
        JSONArray xArray = new JSONArray();
        for (Map map : show) {
            xArray.add(map.get("a"));
        }
        dataobject.put("categories",xArray);

        JSONArray yArray = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","下单金额");

        JSONArray dataArray = new JSONArray();
        for (Map map : show) {
            dataArray.add(map.get("b"));
        }
        jsonObject1.put("data",dataArray);
        yArray.add(jsonObject1);

        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","下单次数");
        JSONArray dataArray1 = new JSONArray();
        for (Map map : show) {
            dataArray1.add(map.get("c"));
        }
        jsonObject2.put("data",dataArray1);
        yArray.add(jsonObject2);

        JSONObject jsonObject3 = new JSONObject();
        jsonObject3.put("name","下单人数");

        JSONArray dataAyyay3 = new JSONArray();
        for (Map map : show) {
            dataAyyay3.add(map.get("c"));
        }

        jsonObject3.put("data",dataAyyay3);
        yArray.add(jsonObject3);

        dataobject.put("series",yArray);


        jsonObject.put("data",dataobject);
        return jsonObject;
    }
    //轮播图
    @RequestMapping("/show1")
    public Object show1(String nowDate){
        List<Map> list = service.show1(nowDate);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONObject dataobject = new JSONObject();
        JSONArray coArray = new JSONArray();
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("name","最近 1/7/30 日");
        jsonObject1.put("id","subsys");
        coArray.add(jsonObject1);

        JSONObject jsonObject2 = new JSONObject();
        jsonObject2.put("name","名字");
        jsonObject2.put("id","module");
        coArray.add(jsonObject2);

        JSONObject jsonObject3 = new JSONObject();
        jsonObject3.put("name","下单次数金额");
        jsonObject3.put("id","business");
        coArray.add(jsonObject3);

        JSONObject jsonObject4 = new JSONObject();
        jsonObject4.put("name","下单金额人数");
        jsonObject4.put("id","name");
        coArray.add(jsonObject4);

        JSONObject jsonObject5 = new JSONObject();
        jsonObject5.put("name","下单人数");
        jsonObject5.put("id","value");
        coArray.add(jsonObject5);

        JSONObject jsonObject6 = new JSONObject();
        jsonObject6.put("name","实收金额");
        jsonObject6.put("id","name1");
        coArray.add(jsonObject6);

        JSONObject jsonObject7 = new JSONObject();
        jsonObject7.put("name","退款完成");
        jsonObject7.put("id","name2");
        coArray.add(jsonObject7);

        dataobject.put("columns",coArray);
        JSONArray roesArray = new JSONArray();
        for (Map map : list) {
            JSONObject rowsobject = new JSONObject();
            rowsobject.put("subsys",map.get("a"));
            rowsobject.put("module",map.get("b"));
            rowsobject.put("business",map.get("c"));
            rowsobject.put("name",map.get("d"));
            rowsobject.put("value",map.get("e"));
            rowsobject.put("name1",map.get("f"));
            rowsobject.put("name2",map.get("g"));
            roesArray.add(rowsobject);

        }
        dataobject.put("rows",roesArray);

        jsonObject.put("data",dataobject);
        return jsonObject;
    }
}
